/**
 * 
 */
package com.pony.util;


import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import me.hao0.wepay.core.Wepay;
import me.hao0.wepay.core.WepayBuilder;
/**
 * @author lpn
 *
 */
public class WxPayUtil {
	private static String appId = "wx0cac58294f4eb471";
	private static String appKey = "123qweasdZXC456rtyfghVBN789uionm";
	private static String mchId = "1442711002";
	private static String certsPath = "./target/classes/apiclient_cert.p12";
	
	private static String payNotifyUrl = "127.0.0.1/wxpay/recive-notify";
	
	private static Wepay wepay= null;
	
	public static Wepay getWepay(){
		if(wepay == null){
			synchronized (WxPayUtil.class){
				if(null == wepay){
					Path path = Paths.get(certsPath);
					byte[] certsData = null;
					try {
						//System.out.println(System.getProperty("user.dir"));
						certsData = Files.readAllBytes(path);
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					wepay = WepayBuilder.newBuilder(
					         appId,appKey,mchId)
					         .certPasswd(mchId)
					         .certs(certsData)
					         .build();
				}
			}
		}
		return wepay;
	}

	public static String getPayNotifyUrl() {
		return payNotifyUrl;
	}

	public static void setPayNotifyUrl(String payNotifyUrl) {
		WxPayUtil.payNotifyUrl = payNotifyUrl;
	}
}
